package actions;

import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import beans.User;

import net.cl.framework.wrappers.ActionContext;

public class Action1 {
	
	private String name;

	public String execute() throws Exception {
		// RequestContext request =
		// ActionContext.getContext().getRequestContext();
		// ResponseContext response =
		// ActionContext.getContext().getResponseContext();
		// response.getResponse().setContentType("text/html; charset=GBK");
		// String ss = request.getRequest().getParameter("tt");
		// System.out.println(ss);

		// PrintWriter out = response.getResponse().getWriter();
		// out.println("<html>");
		// out.println("<head><title>XianLuSerch</title></head>");
		// out.println("<body bgcolor= \"#ffffff\">");
		// out.println("<p>The servlet has received a " +
		// request.getRequest().getMethod() + ss
		// + ". This is the reply.</p>");
		// out.println("<p>" + request.getUserAgent() + "</p>");
		// out.println("</body>");
		// out.println("</html>");
		// out.close();
		Document doc = Jsoup.connect("http://jsoup.org").get();
		name = doc.text();
		Element link = doc.select("a").get(10);
		String relHref = link.attr("href"); // == "/"
		String absHref = link.attr("abs:href"); // "http://jsoup.org/"
		System.out.println(relHref);
		System.out.println(absHref);
		return "/WEB-INF/jsp/index.jsp";
	}

	public String getName() {
		return name;
	}

	public List getList() {
		List list = new ArrayList();
		list.add("1");
		list.add("2");
		return list;
	}

	public User getUser() {
		User u = new User();
		u.setAge(1);
		u.setName("Tom");
		return u;
	}

}
